package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.DeviceParam;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeDeviceParam implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        //*WT,866248053277370,V4,GETPARAM,152129,ver:RY-E15-V1.08,ID:868976030203477,BAT:55,GPS:0,INTERVAL:150,CSQ:99,
        // IP:112.74.176.68,9098,BTFLAG:1,UPLOADFLAG:0,TCPSTATUS:1,GPSSTATUS:1,HEARTBEAT:300,
        // DEFAULTIP:112.74.176.68,9098,MACVALID:3,ASRVER:V,ONENUMBER:ALOE01002732,UID:ALOE01002732,170721,FFFFDFFF
        //解密
        String[] split = parseCommand(originalData);
        String imei = split[1];
        String commandNumber = split[4];
        String firmware = split[5].split(":")[1];
        String id = split[6].split(":")[1];
        Integer battery = Integer.parseInt(split[7].split(":")[1]);
        Integer gpsNum = Integer.parseInt(split[8].split(":")[1]);
        Integer interval = Integer.parseInt(split[9].split(":")[1]);
        Integer csq = Integer.parseInt(split[10].split(":")[1]);
        String ipPort = split[11].split(":")[1] + "," + split[12];
        Integer btfLag = Integer.parseInt(split[13].split(":")[1]);
        Integer uploadFlag = Integer.parseInt(split[14].split(":")[1]);
        Integer tcpStatus = Integer.parseInt(split[15].split(":")[1]);
        Integer gpsStatus = Integer.parseInt(split[16].split(":")[1]);
        Integer heartBeat = Integer.parseInt(split[17].split(":")[1]);
        String defaultIpPort = split[18].split(":")[1] + "," + split[19];
        Integer macValid = Integer.parseInt(split[20].split(":")[1]);
        String asrVer = split[21].split(":")[1];
        String m1Card = split[22].split(":")[1];
        String uId = split[23].split(":")[1];
        String deviceDate = split[24];
        String deviceStatus = split[25];
        DeviceParam mqDeviceParam = new DeviceParam();
        mqDeviceParam.setImei(imei);
        mqDeviceParam.setCommandNumber(commandNumber);
        mqDeviceParam.setAsrVer(asrVer);
        mqDeviceParam.setBattery(battery);
        mqDeviceParam.setBtfLag(btfLag);
        mqDeviceParam.setCsq(csq);
        mqDeviceParam.setDefaultIpPort(defaultIpPort);
        mqDeviceParam.setDeviceDate(deviceDate);
        mqDeviceParam.setFirmware(firmware);
        mqDeviceParam.setDeviceStatus(deviceStatus);
        mqDeviceParam.setGpsNum(gpsNum);
        mqDeviceParam.setGpsStatus(gpsStatus);
        mqDeviceParam.setHeartBeat(heartBeat);
        mqDeviceParam.setInterval(interval);
        mqDeviceParam.setId(id);
        mqDeviceParam.setIpPort(ipPort);
        mqDeviceParam.setM1Card(m1Card);
        mqDeviceParam.setMacValid(macValid);
        mqDeviceParam.setTcpStatus(tcpStatus);
        mqDeviceParam.setUploadFlag(uploadFlag);
        return structureMessage(Constants.REPLY,Constants.CMD_GET_PARAM,false,"",mqDeviceParam);
    }
}
